import { SelectStore } from './selectStore';
import { Router } from '@angular/router';
import { Http } from '@angular/http';
import { LoadMask } from './../../components/loadmask';
import { User } from './viewmodel';
import { NavigateService } from './../../services/navigate';
import { Authentication } from './../../services/authtication';
import { MessageBoxService, GrowlMessageType } from './../../components/messageBox';
import { Component, Directive, ElementRef } from '@angular/core';
import { loadingMask } from './../../components/loadmask';


@Component({
    selector: 'remoteLogin',
    styleUrls: ['./initialization.scss'],
    template: `
        <div class="remotelogin-container">
            <header>
                <i class="material-icons back divvma" (click)="onBack()">arrow_back</i>
                <h1 class="padding">管理登录</h1>
                <div class="nav">
                    <i ></i>
                    <i ></i>
                    <i class="active">3</i>
                    <i ></i>
                    <i ></i>
                </div>
            </header>
            <div class="padding tip ">
                <p class="p1 title">请使用店长或店铺管理员账号登录</p>
            </div>
            <div class="padding form ">
                <input placeholder="请输入账号" [(ngModel)]="user.username" maxLength="100" /> 
                <input placeholder="请输入密码" [(ngModel)]="user.password" type="password" maxLength="100" />
                <button  (click)="login()">登录</button>
            </div>
        </div>
    `,
    providers: []
})

export class RemoteLogin {
    constructor(
        private navSvr: NavigateService,
        private authSvr: Authentication,
        private http: Http,
        private router: Router) {

    }
    private user: User = { username: "", password: "" };
    onBack() {
        this.navSvr.navigate(["initialization/checkEnv"])
    }
    ngOnInit() {
    }

    // @loadingMask()
    private async login() {
        try {
            let r: any = await this.authSvr.storeLogin(this.user.username, this.user.password);
            // this.navSvr.navigate(["setup"]);
            this.navSvr.navigate(["initialization/checkMode"])
        } catch (error) {
            MessageBoxService.current.Growl(GrowlMessageType.Error, "登录失败", "账户名或密码错误");
        }

    }

}
